//
//  InviteDetailViewController.m
//  PCR
//
//  Created by shumei on 16/7/7.
//  Copyright © 2016年 shumei. All rights reserved.
//

#import "InviteDetailViewController.h"
#import "InviteDetailTableViewCell.h"
#import "InviteDetailHeaderView.h"

@interface InviteDetailViewController ()<
UITableViewDataSource,
UITableViewDelegate
>
{
    NSArray * sectionArray;
    UITableView * table_view;
    
}
@end

@implementation InviteDetailViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [[YMBaseTabBarViewController shareInstance] setTabbarHidden];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTopTitleWithTitle:@"邀请明细"];
    [self setLeftItemWithTitle:nil OrImage:@"navLeftBtn.png"];
    sectionArray = [[NSArray alloc]initWithObjects:@"已邀请",@"注册时间",@"购买时间",@"续费时间", nil];
    [self creatTableView];
    
}
-(void)creatTableView
{
    table_view = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,MainSCreen.width , MainSCreen.height - nav_Height ) style:UITableViewStylePlain];
    table_view.delegate = self;
    table_view.dataSource = self;
    [table_view setTableFooterView:[[UIView alloc] init]];
    [self.view addSubview:table_view];
}
#pragma mark ---------------------------------UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1)
    {
        return 7;
    }
    return 1;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2)
    {
        return TableView_Default_SectionHight;
    }
    else if (section == 1)
    {
        return TableView_Default_RowHight;
    }
    return 0.1f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section)
    {
        case 0:
        {
            return 55 / 667.0 * MainSCreen.height;
        }
            break;
        case 1:
        {
            return TableView_Default_RowHight;
        }
            break;
        case 2:
        {
            return [tableView cellHeightForIndexPath:indexPath cellContentViewWidth:MainSCreen.width tableView:tableView];
        }
            break;
        case 3:
        {
            return [tableView cellHeightForIndexPath:indexPath cellContentViewWidth:MainSCreen.width tableView:tableView];
        }
            break;
        default:
            break;
    }
    return 0;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1)
    {
        InviteDetailHeaderView * headerView = [[InviteDetailHeaderView alloc]initWithFrame:CGRectMake(0, 0, MainSCreen.width, TableView_Default_RowHight) withArray:sectionArray];
     
        return headerView;
    }
    return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * First_cell = @"First_cell";
    static NSString * Second_cell = @"Second_cell";
    static NSString * Third_cell = @"Third_cell";
    static NSString * Four_cell = @"Four_cell";
    //累计邀请和累计分成按钮
    if (indexPath.section == 0)
    {
        InviteDetailTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteDetailTableViewCell" owner:self options:nil][0];
        if (!cell)
        {
            cell = [[InviteDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:First_cell];
            
        }
        
        return cell;
    }
    //详情cell
    else if (indexPath.section == 1)
    {
        InviteDetailTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteDetailTableViewCell" owner:self options:nil][1];
        if (!cell)
        {
            cell = [[InviteDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Second_cell];
            
        }
        
        return cell;
    }
    //邀请买手奖励机制
    else if (indexPath.section == 2)
    {
        InviteDetailTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteDetailTableViewCell" owner:self options:nil][2];
        if (!cell)
        {
            cell = [[InviteDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Third_cell];
            
        }
        [cell setupAutoHeightWithBottomView:cell.ThirdCell_DetailLabel bottomMargin:5];
        
        return cell;
    }
    //邀请商家奖励机制
    else
    {
        InviteDetailTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteDetailTableViewCell" owner:self options:nil][3];
        if (!cell)
        {
            cell = [[InviteDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Four_cell];
            
        }
        [cell setupAutoHeightWithBottomView:cell.FourCell_MonthLabel bottomMargin:5];
        
        return cell;
        
    }
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
}





#pragma mark --------------------------------累计邀请，分成按钮的点击事件
-(void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo
{
    NSNumber * num = [userInfo objectForKey:@"tag"];
    if ([num intValue] == 1)
    {
        sectionArray = [[NSArray alloc]initWithObjects:@"已邀请",@"注册时间",@"购买时间",@"续费时间", nil];
    }
    else
    {
        sectionArray = [[NSArray alloc]initWithObjects:@"日期",@"邀请买手",@"邀请商家",@"累计获得", nil];
    }
    NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
    [table_view reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
